class Solution(object):
    def hammingWeight(self, n):
        """
        :type n: int
        :rtype: int
        """
        # 法一
        # bin_str = bin(n)[2:]
        # return bin_str.count('1')
        # 法二：位运算
        count = 0
        while n:
            count += n & 1
            n >>= 1
        return count
if __name__ == '__main__':
    s = Solution()
    print(s.hammingWeight(11))